package com.sunther.document.controller;

import com.sunther.document.entity.FileSystemEntity;
import com.sunther.document.entity.FileSystemMidEntity;
import com.sunther.document.service.FileSystemMidService;
import com.sunther.document.service.FileSystemService;
import com.sunther.idb.common.util.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author csb
 * @description: TODO 文件体系
 * @date 2023/5/17 16:14
 */
@RestController
@RequestMapping("/file_system")
public class FileSystemController {

    @Autowired
    private FileSystemService fileSystemService;

    @Autowired
    private FileSystemMidService fileSystemMidService;

    @GetMapping("/list")
    public WebResult list(@RequestParam String keyword){
        try {
            return WebResult.success("操作成功",fileSystemMidService.listByKeyword(keyword));
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

    @PostMapping("/save")
    public WebResult save(@RequestBody FileSystemMidEntity data, HttpServletRequest request) {
        try {
            return fileSystemService.saveData(data,request);
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

    @GetMapping("/detail")
    public WebResult detail(@RequestParam String id){
        try {
            return WebResult.success("操作成功",fileSystemService.detail(id));
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

    @GetMapping("/project_by_dtl")
    public WebResult projectByDtl(@RequestParam String projectId, HttpServletRequest request){
        try {
            return fileSystemService.projectByDtl(projectId, request);
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

    @GetMapping("/del_mid")
    public WebResult delMid(@RequestParam String id){
        try {
            return fileSystemMidService.delMid(id);
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

    @GetMapping("/del_detail")
    public WebResult delDetail(@RequestParam String id){
        try {
            return fileSystemService.delDetail(id);
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }
}
